package com.example.zhanghao.controller;

import com.example.zhanghao.DTO.TypeDto;
import com.example.zhanghao.Entity.Type;
import com.example.zhanghao.VO.CommonVo;
import com.example.zhanghao.VO.TypeVo;
import com.example.zhanghao.mapper.TypeMapper;
import com.example.zhanghao.services.impl.TypeServiceImpl;
import com.example.zhanghao.utils.CopyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController //这是返回接口
@RequestMapping("/type")
public class TypeController {

    private static final Logger LOG = LoggerFactory.getLogger(TypeController.class);

    @Resource
    TypeServiceImpl typeServiceImpl;

    @Resource
    TypeMapper typeMapper;

     @GetMapping("/all")
     public CommonVo<List<TypeVo>> all(@Valid TypeDto req){
         List<Type> typeLists =  typeServiceImpl.list();
         CommonVo<List<TypeVo>> typeCommonVo  = new CommonVo<>();
         typeCommonVo.setData(CopyUtil.copyList(typeLists,TypeVo.class));
         return typeCommonVo;
     }
    @GetMapping("/selectTypeWithAccounts")
    public CommonVo<List<TypeVo>> selectTypeWithAccountsC(){
         CommonVo<List<TypeVo>> typeCommonVo = new CommonVo<>();
         typeCommonVo.setData(typeMapper.selectTypeWithAccounts());
         return typeCommonVo;
    }
}

